package car.aistar.service.impl;

import car.aistar.dto.CarOverview;
import car.aistar.dto.LaoxuPersonDto;
import car.aistar.service.LaoxuPersonService;
import car.aistar.service.PersonCenterService;
import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @ClassName PersonCenterServiceImpl
 * @Description TODO 浏览记录分页
 * @Author laoxu
 * @Date 2020/10/8 16:18
 * Version 1.0
 **/
@Service("PersonCenterService")
public class PersonCenterServiceImpl implements PersonCenterService {

    @Autowired
    private LaoxuPersonService laoxuPersonService;

    @Override
    public List<CarOverview> queryByHistory(Long uid) {
        List<LaoxuPersonDto> laoxuPersonList = laoxuPersonService.queryByHistory(uid);
        List<CarOverview> carOverviewList = new ArrayList<>();
        for (LaoxuPersonDto c : laoxuPersonList) {
            CarOverview carOverview = new CarOverview();
            Date d = c.getcRegistration();
            int y = DateUtil.year(d);
            carOverview.setcRegistration(y);
            carOverview.setId(c.getId());
            carOverview.setcOprice(c.getcOprice());
            carOverview.setcStatus(c.getcStatus());
            carOverview.setStName(c.getStName());
            carOverview.setBrName(c.getBrName());
            carOverview.setcPaifang(c.getcPaifang());
            carOverview.setcDrive(c.getcDrive());
            carOverview.setcMileage(c.getcMileage());
            carOverview.setcPhoto(c.getcPhoto());
            carOverviewList.add(carOverview);
        }
        return carOverviewList;
    }

    @Override
    public PageInfo<CarOverview> queryPageHistory(Long uid, String pageNow, String pageSize) {
        PageHelper.startPage(Integer.valueOf(pageNow),Integer.valueOf(pageSize));
        List<CarOverview> carOverviewList = queryByHistory(uid);
        PageInfo<CarOverview> viewPageInfo = new PageInfo<>(carOverviewList);
        return viewPageInfo;
    }
}
